import { useUserStore } from "@renderer/stores/user"
import { Directive, DirectiveBinding } from "vue"

// 自定义按钮权限指令
const auths: Directive = (el: Element, binding: DirectiveBinding<string>) => {
	// 获取用户仓库
	const userStore = useUserStore()
	const { permissions } = userStore
	// 拥有所有权限，则不用判断
	if (permissions.includes("*:*:*")) return

	// 权限数组中不包含绑定的值则从父节点中移除该节点
	if (!permissions.includes(binding.value)) {
		el.parentNode?.removeChild(el)
	}
}

export default auths